package com.scada.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.scada.dao.ILectureMemberDao;
import com.scada.inf.LectureMemberVisitor;
import com.scada.model.bean.LectureMember;
import com.scada.model.bean.MemberInfo;
import com.scada.model.result.ResponseBean;
import com.scada.model.search.LectureChooseMemberSearch;
import com.scada.model.search.LectureNotChooseMemberSearch;

@Service("lectureMemberVisitorService")
@WebService
@SOAPBinding(style = Style.RPC)
public class LectureMemberVisitorImpl implements LectureMemberVisitor{

	@Autowired
	private ILectureMemberDao lectureMemberDao;
	
	@Transactional
	@Override
	public void deleteLectureMemberById(String ids) {
		
		try {
			for(String id : ids.split(",")) {
				lectureMemberDao.deleteLectureMemberById(Long.parseLong(id));
			}
		}catch (Exception e) {
			throw new RuntimeException();
		}
	}

	@Override
	public void insertLectureMember(String memberIds, Long lectureId, Integer lectureType) {
		
		try {
			LectureMember lectureMember = null;
			for(String memberId : memberIds.split(",")) {
				lectureMember = LectureMember.builder().memberId(Long.parseLong(memberId)).lectureId(lectureId).lectureType(lectureType).build();
				lectureMemberDao.insertLectureMember(lectureMember);
			}
		}catch (Exception e) {
			throw new RuntimeException();
		}
		
	}

	@Override
	public ResponseBean getNotChooseMemberPageData(LectureNotChooseMemberSearch lectureNotChooseMemberSearch) {
		
		ResponseBean responseBean = new ResponseBean();
		Map<String,Object> map = new HashMap<String,Object>();
		try{
			map.put("isShow", MemberInfo.IsShowCode.YES.getKey());
			map.put("lectureId", lectureNotChooseMemberSearch.getLectureId());
			map.put("memberName", lectureNotChooseMemberSearch.getMemberName());
			map.put("enName", lectureNotChooseMemberSearch.getEnName());
			map.put("sex", lectureNotChooseMemberSearch.getSex());
			map.put("mobile", lectureNotChooseMemberSearch.getMobile());
			map.put("wechatNum", lectureNotChooseMemberSearch.getWechatNum());
			map.put("custType", lectureNotChooseMemberSearch.getCustType());
			map.put("lectureNotice", lectureNotChooseMemberSearch.getLectureNotice());
			responseBean.addObject("resultCount", lectureMemberDao.getNotChooseMemberPageCount(map));
			map.put("start", lectureNotChooseMemberSearch.getStart());
			map.put("pageSize", lectureNotChooseMemberSearch.getLength());
            responseBean.addObject("resultList", lectureMemberDao.getNotChooseMemberPageList(map));
			responseBean.success();
		}catch(Exception e){
			responseBean.failed();
		}
		return responseBean;
	}

	@Override
	public ResponseBean getChooseMemberPageData(LectureChooseMemberSearch lectureChooseMemberSearch) {
		
		ResponseBean responseBean = new ResponseBean();
		Map<String,Object> map = new HashMap<String,Object>();
		try{
			map.put("isShow", MemberInfo.IsShowCode.YES.getKey());
			map.put("lectureId", lectureChooseMemberSearch.getLectureId());
			map.put("memberName", lectureChooseMemberSearch.getMemberName());
			map.put("enName", lectureChooseMemberSearch.getEnName());
			map.put("sex", lectureChooseMemberSearch.getSex());
			map.put("mobile", lectureChooseMemberSearch.getMobile());
			map.put("wechatNum", lectureChooseMemberSearch.getWechatNum());
			map.put("custType", lectureChooseMemberSearch.getCustType());
			map.put("lectureNotice", lectureChooseMemberSearch.getLectureNotice());
			responseBean.addObject("resultCount", lectureMemberDao.getChooseMemberPageCount(map));
			map.put("start", lectureChooseMemberSearch.getStart());
			map.put("pageSize", lectureChooseMemberSearch.getLength());
            responseBean.addObject("resultList", lectureMemberDao.getChooseMemberPageList(map));
			responseBean.success();
		}catch(Exception e){
			responseBean.failed();
		}
		return responseBean;
	}

	@Override
	public ResponseBean getLectureMemberNumber(Long lectureId) {
		
		ResponseBean responseBean = new ResponseBean();
		try{
			responseBean.addObject("result", lectureMemberDao.getLectureMemberNumber(lectureId));
			responseBean.success();
		}catch(Exception e){
			responseBean.failed();
		}
		return responseBean;
	}

}
